#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ll t; cin >> t;
	while (t--) {
		ll n; cin >> n;
		ll mx = 0;
		int pos = 0;
		for (int i = 1; i <= n; i++) {
			ll a, b; cin >> a >> b;
			if (a > 10) continue;
			else {
				if (b > mx) {
					mx = max(mx, b);
					pos = i;
				}
			}
		}
		cout << pos << endl;
	}
	return 0;
}